 

package com.zdkj.subway.rca.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdkj.admin.api.entity.SysUser;
import com.zdkj.admin.api.vo.UserVO;
import com.zdkj.common.core.constant.CommonConstants;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;

import com.zdkj.common.security.service.PigxUser;
import com.zdkj.common.security.util.SecurityUtils;
import com.zdkj.subway.rca.dto.in.UserDto;
import com.zdkj.subway.rca.entity.*;
import com.zdkj.subway.rca.service.*;
import com.zdkj.subway.rca.util.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;


/**
 * 非现金收入审核-多元化支付平台数据审核
 *
 * @author stw
 * @date 2020-10-29 10:35:47
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swckdistinctpayment" )
@Api(value = "swckdistinctpayment", tags = "非现金收入审核-多元化支付平台数据审核管理")
public class SwCkDistinctPaymentController {

    private final SwCkDistinctPaymentService swCkDistinctPaymentService;

    @Autowired
    private SwCkDistinctPaymentQrService swCkDistinctPaymentQrService;
    @Autowired
    private SwCkDistinctPaymentQrTmpService swCkDistinctPaymentQrTmpService;

    @Autowired
    private SwCkDistinctPaymentTvmService swCkDistinctPaymentTvmService;
    @Autowired
    private SwCkDistinctPaymentTvmTmpService swCkDistinctPaymentTvmTmpService;

    @Autowired
    private SwCkDistinctPaymentFaceService swCkDistinctPaymentFaceService;
    @Autowired
    private SwCkDistinctPaymentFaceTmpService swCkDistinctPaymentFaceTmpService;

	@Autowired
    private SwCkDistinctPaymentConnectivityService swCkDistinctPaymentConnectivityService;
    @Autowired
    private SwCkDistinctPaymentConnectivityTmpService swCkDistinctPaymentConnectivityTmpService;

    /**
     * 分页查询
     * @param page 分页对象
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public R getSwCkDistinctPaymentPage(Page page, String startDate, String endDate) {
        SwCkDistinctPayment swCkDistinctPayment = new SwCkDistinctPayment();

        return R.ok(swCkDistinctPaymentService.page(page, Wrappers.query(swCkDistinctPayment).lambda().ge(StringUtils.isNotEmpty(startDate), SwCkDistinctPayment::getTradeDate, startDate).le( StringUtils.isNotEmpty(endDate), SwCkDistinctPayment::getTradeDate, endDate).orderByDesc(SwCkDistinctPayment::getTradeDate)));
    }

    /**
     * 导出模板
     * @param
     * @return
     * @throws IOException
     */
    @ApiOperation(value = "导出模板,verfiyConfirmFlag：1、微信支付宝银联；2、TVM，3、人脸， 4、应急及互联互通", notes = "导出模板,verfiyConfirmFlag： 1、微信支付宝银联；2、TVM，3、人脸， 4、应急及互联互通")
    @GetMapping({"/exportTamplates"})
    @PreAuthorize("@pms.hasPermission('sw_ck_distinct_payment_import')")
    public void exportTamplates(String verfiyConfirmFlag, HttpServletResponse response) {
        swCkDistinctPaymentService.exportTamplates(verfiyConfirmFlag,response);
    }

    /**
     * 批量导入对账确认表
     * @param file
     * @param verfiyConfirmFlag
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "批量导入对账确认表,verfiyConfirmFlag：1、微信支付宝银联；2、TVM，3、人脸， 4、应急及互联互通", notes = "批量导入对账确认表,verfiyConfirmFlag： 1、微信支付宝银联；2、TVM，3、人脸， 4、应急及互联互通")
    @SysLog("批量导入对账确认表")
    @PostMapping(value = "/saveBatch",  headers = "content-type=multipart/form-data")
    @PreAuthorize("@pms.hasPermission('sw_ck_distinct_payment_import')")
    public R saveBatch(@RequestParam(value = "file") MultipartFile file, @RequestParam String verfiyConfirmFlag) throws Exception {
        return R.ok((Object)this.swCkDistinctPaymentService.saveBatchWithExcel(file,verfiyConfirmFlag));
    }

    /**
     * 导入后确认表列表查询
     * @return
     */
    @ApiOperation(value = "导入后确认表列表查询", notes = "导入后确认表列表查询")
    @GetMapping("/listConfirmTable" )
    @PreAuthorize("@pms.hasPermission('sw_ck_distinct_payment_import')")
    public R getSwCkDistinctPaymentConfirmTableList() {
        List<Map<String,String>> list = swCkDistinctPaymentService.getSwCkDistinctPaymentConfirmTableList();
        return R.ok(list);
    }


    /**
     * 各个确认表导入预处理分页查询
     * @return
     */
    @ApiOperation(value = "各个确认表导入预处理分页查询", notes = "各个确认表导入预处理分页查询")
    @GetMapping("/listPreprocessing" )
    @PreAuthorize("@pms.hasPermission('sw_ck_distinct_payment_import')")
    public R listPreprocessing(Page page, String verfiyConfirmFlag) {
        PigxUser user = SecurityUtils.getUser();
        if("1".equals(verfiyConfirmFlag)) { //多元化支付平台审核-微信支付宝银联
            SwCkDistinctPaymentQrTmp swCkDistinctPaymentQrTmp = new  SwCkDistinctPaymentQrTmp();
            swCkDistinctPaymentQrTmp.setCreatorId(user.getId());
            return R.ok(swCkDistinctPaymentQrTmpService.page(page,Wrappers.query(swCkDistinctPaymentQrTmp)));
        } else if("2".equals(verfiyConfirmFlag)) { //多元化支付平台审核-TVM
            SwCkDistinctPaymentTvmTmp swCkDistinctPaymentTvmTmp = new  SwCkDistinctPaymentTvmTmp();
            swCkDistinctPaymentTvmTmp.setCreatorId(user.getId());
            return R.ok(swCkDistinctPaymentTvmTmpService.page(page,Wrappers.query(swCkDistinctPaymentTvmTmp)));
        } else if("3".equals(verfiyConfirmFlag)) { //多元化支付平台审核-人脸
            SwCkDistinctPaymentFaceTmp swCkDistinctPaymentFaceTmp = new  SwCkDistinctPaymentFaceTmp();
            swCkDistinctPaymentFaceTmp.setCreatorId(user.getId());
            return R.ok(swCkDistinctPaymentFaceTmpService.page(page,Wrappers.query(swCkDistinctPaymentFaceTmp)));
        } else if("4".equals(verfiyConfirmFlag)) { //多元化支付平台审核-应急及互联互通
            SwCkDistinctPaymentConnectivityTmp swCkDistinctPaymentConnectivityTmp = new  SwCkDistinctPaymentConnectivityTmp();
            swCkDistinctPaymentConnectivityTmp.setCreatorId(user.getId());
            return R.ok(swCkDistinctPaymentConnectivityTmpService.page(page,Wrappers.query(swCkDistinctPaymentConnectivityTmp)));
        } else {
            return R.ok();
        }

    }
    /**
     * 各个确认表导入预处理确认
     * @param verfiyConfirmFlag
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "各个确认表导入预处理确认", notes = "各个确认表导入预处理确认")
    //@SysLog("确认表导入预处理确认")
    @GetMapping({ "/saveBatchOk" })
    //@PreAuthorize("@pms.hasPermission('sw_ck_distinct_payment_import')")
    public R saveBatchOk(@RequestParam String verfiyConfirmFlag) throws Exception {
        PigxUser pigxUser = SecurityUtils.getUser();
        UserDto user = new UserDto();
        if(pigxUser == null){
            user = UserUtil.userDto();
        }else {
            user = UserUtil.pigxUser();
        }
        if("1".equals(verfiyConfirmFlag)) {
            this.swCkDistinctPaymentQrTmpService.saveBatchWithExcelOk(user.getId());

        } else if("2".equals(verfiyConfirmFlag)) {
            this.swCkDistinctPaymentTvmTmpService.saveBatchWithExcelOk(user.getId());

        } else if("3".equals(verfiyConfirmFlag)) {
            this.swCkDistinctPaymentFaceTmpService.saveBatchWithExcelOk(user.getId());

        } else if("4".equals(verfiyConfirmFlag)) {
            this.swCkDistinctPaymentConnectivityTmpService.saveBatchWithExcelOk(user.getId());

        }  else {
            return R.ok(false);
        }

        return R.ok(true);
    }
    /**
     * 各个确认表导入预处理取消
     * @param verfiyConfirmFlag
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "各个确认表导入预处理取消", notes = "各个确认表导入预处理取消")
    @SysLog("确认表导入预处理取消")
    @GetMapping({ "/saveBatchCancel" })
    @PreAuthorize("@pms.hasPermission('sw_ck_distinct_payment_import')")
    public R saveBatchCancel(@RequestParam String verfiyConfirmFlag) throws Exception {
        PigxUser user = SecurityUtils.getUser();
        if("1".equals(verfiyConfirmFlag)) {
            this.swCkDistinctPaymentQrTmpService.saveBatchWithExcelCancel(user.getId());

        } else if("2".equals(verfiyConfirmFlag)) {
            this.swCkDistinctPaymentTvmTmpService.saveBatchWithExcelCancel(user.getId());

        } else if("3".equals(verfiyConfirmFlag)) {
            this.swCkDistinctPaymentFaceTmpService.saveBatchWithExcelCancel(user.getId());

        } else if("4".equals(verfiyConfirmFlag)) {
            this.swCkDistinctPaymentConnectivityTmpService.saveBatchWithExcelCancel(user.getId());

        }  else {
            return R.ok(false);
        }

        return R.ok(true);
    }

    /**
     * 各个确认表分页预览
     * @return
     */
    @ApiOperation(value = "各个确认表分页预览", notes = "各个确认表分页预览")
    @GetMapping("/listPreview" )
    @PreAuthorize("@pms.hasPermission('sw_ck_distinct_payment_import')")
    public R listPreview(Page page, String tradeDate,String verfiyConfirmFlag) throws Exception {
        if(StringUtils.isEmpty(tradeDate) || StringUtils.isEmpty(verfiyConfirmFlag)){
            return R.ok(CommonConstants.FAIL);
        }

        if("1".equals(verfiyConfirmFlag)) {
            SwCkDistinctPaymentQr swCkDistinctPaymentQr = new SwCkDistinctPaymentQr();
            return R.ok(swCkDistinctPaymentQrService.page(page,Wrappers.query(swCkDistinctPaymentQr).lambda().eq(SwCkDistinctPaymentQr::getTradeDate,tradeDate)));
        } else if("2".equals(verfiyConfirmFlag)) {
            SwCkDistinctPaymentTvm swCkDistinctPaymentTvm = new SwCkDistinctPaymentTvm();
            return R.ok(swCkDistinctPaymentTvmService.page(page,Wrappers.query(swCkDistinctPaymentTvm).lambda().eq(SwCkDistinctPaymentTvm::getTradeDate,tradeDate)));
        } else if("3".equals(verfiyConfirmFlag)) {
            SwCkDistinctPaymentFace swCkDistinctPaymentFace = new SwCkDistinctPaymentFace();
            return R.ok(swCkDistinctPaymentFaceService.page(page,Wrappers.query(swCkDistinctPaymentFace).lambda().eq(SwCkDistinctPaymentFace::getTradeDate,tradeDate)));
        } else if("4".equals(verfiyConfirmFlag)) {
            SwCkDistinctPaymentConnectivity swCkDistinctPaymentConnectivity = new SwCkDistinctPaymentConnectivity();
            return R.ok(swCkDistinctPaymentConnectivityService.page(page,Wrappers.query(swCkDistinctPaymentConnectivity).lambda().eq(SwCkDistinctPaymentConnectivity::getTradeDate,tradeDate)));
        }  else {
            return R.ok();
        }

    }
}
